﻿using CPPEI.ETL.WebApi.DataContracts.List;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace CPPEI.ETL.WebApi.ApiControllers
{
    public class ListController : ApiController
    {
        [HttpGet]
        public ListResult<TaskCategory> RootTaskCategory()
        {
            ListResult<Domain.Entities.ETaskCategory> serResult = new Domain.Services.ListService().ListRootTaskCategory();
            if (serResult.IsSuccess == false)
            {
                return new ListResult<TaskCategory>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message);
            }

            List<TaskCategory> list = new List<TaskCategory>();
            for (int index = 0; index < serResult.Data.Count; index++)
            {
                TaskCategory item = new TaskCategory();
                item.Id = serResult.Data[index].Id;
                item.Code = serResult.Data[index].Code;
                item.Name = serResult.Data[index].Name;
                list.Add(item);
            }
            return new ListResult<TaskCategory>(true, 0, string.Empty, list);
        }

        [HttpGet]
        public ListResult<TaskCategory> SubTaskCategory(Guid parentId)
        {
            ListResult<Domain.Entities.ETaskCategory> serResult = new Domain.Services.ListService().ListSubTaskCategory(parentId);
            if (serResult.IsSuccess == false)
            {
                return new ListResult<TaskCategory>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message);
            }

            List<TaskCategory> list = new List<TaskCategory>();
            for (int index = 0; index < serResult.Data.Count; index++)
            {
                TaskCategory item = new TaskCategory();
                item.Id = serResult.Data[index].Id;
                item.Code = serResult.Data[index].Code;
                item.Name = serResult.Data[index].Name;
                list.Add(item);
            }
            return new ListResult<TaskCategory>(true, 0, string.Empty, list);
        }
    }
}
